<!DOCTYPE html>
<html>
<head lang="zh-CN">
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="keywords" content="">
<meta name="description" content="">
<meta name="format-detection" content="telephone=no, email=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" href="<%=basePath%>favicon.ico" />

<title>支付</title>
<link rel="stylesheet" href="<%=basePath%>css/common/normalize.css">
<link rel="stylesheet" href="<%=basePath%>css/common/iconfont.css">
<link rel="stylesheet" href="<%=basePath%>css/cart.css">
<link rel="stylesheet"
	href="<%=basePath%>css/plugin/swiper.css-v=201601281128.css">
</head>
<body>
	<div class="m-wrapper">

		<jsp:include page="header_member.jsp"></jsp:include>

		<div id="box-main" class="m-main box-tab">
			<c:forEach items="${address_list}" var="addr">
				<dl class="lz-address">
					<dd class="addr-check">
						<h3>
							<input type="radio" name="addressid" value="${addr.id}"
								<c:if test="${addr.enable==0}">checked="checked"</c:if>>
						</h3>
					</dd>
					<dd class="addr-detail">
						<div class="addr-name-tel">
							<b><span>${addr.name}</span>${addr.phone}</b>
						</div>
						<div class="addr">${addr.address}</div>
					</dd>
				</dl>
				<div class="clear"></div>
			</c:forEach>

			<div class="m-cart" style="padding: 10px;">
				<div class="m-list">
					<ul class="clear-fix">
						<c:forEach items="${datas.shopList}" var="shopList">
							<c:forEach items="${shopList.carList}" var="car">
								<li>
									<dl>
										<dd>
											<input name="c_id" type="hidden" value="${car.c_id}">
											<input name="product_id" type="hidden"
												value="${car.product_id}"> <a
												href="<%=basePath%>mobile/goodsdetail?id=${car.goods_id}">
												<img class="lazy" src="<%=imagePath%>${car.image}" alt="">
											</a>
										</dd>
										<dd>
											<div class="product-note">${car.goodName}<br />
											</div>
											<div class="product-price">
												&yen;
												<fmt:formatNumber value="${car.price*car.count}"
													pattern="#0.00" />
												<span style="float: right">X ${car.count}</span>
											</div>
										</dd>
									</dl>
									<div class="clear"></div>
								</li>


							</c:forEach>
						</c:forEach>
					</ul>
				</div>
			</div>

			<div class="m-pay-type mt10">
				<div class="lz-title mt20  lz-bottom-line">
					<h3>
						<i class="icon-uthink-01"></i>支付方式
					</h3>
				</div>
				<div class="lz-pay">
					<dl>
						<dd>
							<input name="pay_type" type="radio" checked="checked" value="2" />
							微信支付
						</dd>
						<!-- <dd>
							<input name="pay_type" type="radio" value="1" /> 支付宝支付
						</dd> -->
						<dd>
							<input name="pay_type" type="radio" value="0" /> 线下支付
						</dd>
					</dl>
				</div>
			</div>

			<div class="m-product">
				<span id="goods_counts" class="notice"></span> 件商品 应付金额 合计： <span
					id="total_prices" class="notice">￥<fmt:formatNumber
						value="${datas.sumPrice}" pattern="#0.00" /></span>
			</div>

		</div>
		<!--正文:end-->

		<form id="paydata" style="display: none;">
			<input name="c_ids" id="c_ids" value=""> <input
				name="product_ids" id="product_ids" value=""> <input
				name="address_id" id="address_id" value=""> <input
				name="remark" id="remark" value=""> <input name="payType"
				id="payType" value=""> <input name="sumPrice" id="sumPrice"
				value="${datas.sumPrice}"> <input name="sendfee"
				id="sendfee" value="10">
		</form>

		<div id="box-footer" class="m-footer box-tab">
			<button type="button" class="btn_confirm" onclick="createOrder()">确认支付</button>
		</div>
	</div>

	<div id="mask"></div>
	<script type="text/javascript"
		src="<%=basePath%>js/zepto.min.js-v=201601281128"></script>
	<script type="text/javascript"
		src="<%=basePath%>js/util.js-v=201601281128"></script>
	<script type="text/javascript"
		src="<%=basePath%>js/head.js-v=201601281128"></script>
	<script type="text/javascript"
		src="<%=basePath%>js/extend/swiper.min.js-v=201601281128"></script>
	<script>
		$(function(){
			$("#header_title").html("确认支付");
			$("#goods_counts").html($("div[class='cart_list_item']").length);
		})
		
		function createOrder(){
			<%-- $.ajax({
				url : "<%=basePath%>mobile/demopackage",
				success : function(jsapi) {
					var info = eval('('+jsapi+')');
						WeixinJSBridge.invoke('getBrandWCPayRequest',info,
							function(res){
								//支付成功或失败前台判断
						    		if(res.err_msg=='get_brand_wcpay_request:ok'){
						    	    		alert('恭喜您，支付成功!');
						    	    }else{
						    	    	   	alert('支付失败');
						    	    }
							});
				}
			}); --%>
			var paytype = $("input[name='pay_type']:checked").val();
			$("#payType").val(paytype);
			
			var cids = new Array();
			$("input[name='c_id']").each(function(){
				cids.push($(this).val());
			})
			$("#c_ids").val(cids.join(","));
			
			var productids= new Array();
			$("input[name='product_id']").each(function(){
				productids.push($(this).val());
			})
			$("#product_ids").val(productids.join(","));
			
			$("#address_id").val($("input[name='addressid']:checked").val());
			
			$.ajax({
				type:"post",
				url:"<%=basePath%>mobile/createOrder",
				data : $("#paydata").serialize(),
				success : function(msg) {
					var info = eval('(' + msg + ')');
					if (info.error == "0000") {
						var orderids = info.orderid;
						var paymoney = info.paymoney;
						if (paytype == "0") {//跳转到线下支付确认页面
							window.location.href="<%=basePath%>mobile/my_orders";
						} else if (paytype == "1") {//跳转到支付宝支付界面
							/* $("#WIDout_trade_no").val(orderids);
							$("#WIDsubject").val("购买商品");
							$("#WIDtotal_fee").val(info.datas.sumPrice);
							document.getElementById("alipayment").submit(); */
						} else {//跳转到微信支付页面
							$.ajax({
								url : "<%=basePath%>mobile/payConfig",
												data : {
													ordertitle : orderids,
													total : paymoney
												},
												dataType : "json",
												success : function(jsapi) {
													/* alert(JSON.stringify(jsapi)) */
													if (jsapi.error == "1111") {
														alert(jsapi.information);
													} else {
														WeixinJSBridge
																.invoke(
																		'getBrandWCPayRequest',
																		{
																			"appId" : jsapi.appId, // 公众号名称，由商户传入
																			"timeStamp" : jsapi.timeStamp, // 时间戳，自1970 年以来的秒数
																			"nonceStr" : jsapi.nonceStr, // 随机串
																			"package" : jsapi.package, // 预支付ID
																			"signType" : jsapi.signType, // 微信签名方式:
																			"paySign" : jsapi.paySign
																		// 微信签名
																		},
																		function(
																				res) {
																			if (res.err_msg == "get_brand_wcpay_request:ok") {
																				alert("支付成功");
																				location.href = "<%=basePath%>mobile/my_orders"; 
																			}
																		});
													}
												}
											});
								}
							} else {
								alert(info.information);
							}
						}
					}) 
		}
	</script>
</body>
</html>

